package com.szeldon.pj.jps.qres;

import com.szeldon.pj.jps.datastore.SBAObjectId;

public class ReferenceResult extends AbstractQueryResult {
	private SBAObjectId objectId;

	/**
	 * 
	 * @param objectId
	 */
	public ReferenceResult(SBAObjectId objectId) {
		this.objectId = objectId;
	}

	@Override
	public String toString() {
		return "ref(" + objectId + ")";
	}

	public SBAObjectId getReferencedObjectId() {
		return objectId;
	}

	@Override
	public int compareTo(AbstractQueryResult result) {
		if (result instanceof ReferenceResult) {
			return objectId.compareTo(((ReferenceResult) result).getReferencedObjectId());
		} else {
			throw new IllegalStateException("Reference result can't be compared with " + result.getClass().getName()
					+ " result.");
		}
	}

	@Override
	public boolean equals(Object obj) {
		if (obj.getClass().equals(this.getClass())) {
			ReferenceResult objResult = (ReferenceResult) obj;
			if (objectId.equals(objResult.getReferencedObjectId())) {
				return true;
			} else {
				return false;
			}
		} else {
			return false;
		}
	}
}
